<template>
	<view class="content">
		<uni-collapse accordion="true">
		    <uni-collapse-item :title="item.date" v-for="(item,index) in listData" :key="index" :incomeTotal='item.incomeTotal' :expenditureTotal="item.expenditureTotal">
		        <view class="with_module">
		           <view class="with_module_item" v-for="(a,i) in item.data" :key="i">
		           	  <view class="with_module_lf">
		           	  	<text>{{a.smsTitle}}</text>
		           	  	<text>{{a.createTime}}</text>
		           	  </view>
					  <text class="money">{{a.smsStatus==0?'+':a.smsStatus==1?'-':''}}{{a.smsContent}}</text>
		           </view>
				 
		        </view>
		    </uni-collapse-item>
		   <!-- <uni-collapse-item title="2020年8月">
		        <view style="padding: 30rpx;">
		            手风琴效果
		        </view>
		    </uni-collapse-item>
		    <uni-collapse-item title="2020年7月">
		        <view style="padding: 30rpx;">
		            手风琴效果
		        </view>
		    </uni-collapse-item> -->
		</uni-collapse>
		<!-- <view class="with_detail">
			<view class="with_detail_item">
				<view class="with_detail_title">
					<text>2020年8月</text>
					<image src="../../static/img/down.png" style="width: 20rpx;height: 10rpx;" mode=""></image>
				</view>
				
			</view>
		</view> -->
		<view >
			<uni-load-more :status="loadStatus"></uni-load-more>
		</view>
	</view>
</template>

<script>
	import myMixin from "../../static/js/mixin.js"
	export default{
		data(){
			return {
				
			}
		},
		mixins: [myMixin],
		onShow() {
			
		},
		methods:{
			initData(){
				this.$http.get(`/api/user/userIntegralDetails`,{
					areaCode:this.cityCode,
					type:1,
					pageRow:this.pageRow,
					pageSize:this.pageSize
				}).then((data)=>{
					if(data.data.code==200){
						if(this.pageRow!=1){
							this.listData=this.listData.concat(this.changeData(data.data.result.records));
						}else{
							this.listData=this.changeData(data.data.result.records);
							
						}
						if (data.data.result.records.length) {
							if (data.data.result.records.length < this.pageSize) { //判断接口返回数据量小于请求数据量，则表示此为最后一页
								this.isLoadMore = true
								this.loadStatus = 'nomore';
								
							} else {
								this.isLoadMore = false;
								this.loadStatus = 'more';
							}
						} else {
							this.isLoadMore = true
							this.loadStatus = 'nomore'
						}
					}
				}).catch(()=>{
					this.isLoadMore = true
					this.loadStatus = 'nomore'
				})
			},
			changeData(list){
				
				let dateArr=list.map((a)=>{
					return a.createTime;
				});
				
				let arr=[];
				let dateObjArr=[];
				arr=[...new Set(dateArr)];
				
				arr.forEach((a,i)=>{
					let obj={
						data:[],
						date:'',
						incomeTotal:0,
						expenditureTotal:0
					};
					if(a){
						obj.date=a.split(' ')[0].slice(0,7);
						dateObjArr.push(obj);
					}
					
				})
				
				list.forEach((a,i)=>{
					dateObjArr.forEach((m,n)=>{
						if(a.createTime.indexOf(m.date)!=-1){
							m.data.push(a)
							
						}
					})
				})
				dateObjArr.forEach((a,i)=>{
					a.data.forEach((m,n)=>{
						if(m.smsStatus==0){//收入
							a.incomeTotal+=Number(m.smsContent)
						}else if(m.smsStatus==1){//支出
							a.expenditureTotal+=Number(m.smsContent)
						}
					})
				})
				console.log(dateObjArr)
				return dateObjArr;
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/css/pointsDetails.scss'
</style>
